package com.rocket;

import com.alibaba.rocketmq.client.producer.DefaultMQProducer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description: 生产者配置
 * @Author: suzr
 * @Date: 2019-6-10 15:09
 * @return:
 * @throws:
 */
@Configuration
public class ProducerConfig {
   /* private  static final Logger log= LoggerFactory.getLogger(ProducerConfig.class);
    @Value("${rocketmq.producer.groupName}")
    private String groupName;
    @Value("${rocketmq.producer.namesrvAddr}")
    private String namesrvAddr;
    @Value("${rocketmq.producer.maxMessageSize}")
    private Integer maxMessageSize ;
    @Value("${rocketmq.producer.sendMsgTimeout}")
    private Integer sendMsgTimeout;
    @Value("${rocketmq.producer.retryTimesWhenSendFailed}")
    private Integer retryTimesWhenSendFailed;

    @Bean
    public DefaultMQProducer getRocketMQProducer(){
        DefaultMQProducer producer;
        producer=new DefaultMQProducer(this.groupName);
        producer.setNamesrvAddr(this.namesrvAddr);
        if(this.maxMessageSize != null)  {
            producer.setMaxMessageSize(this.maxMessageSize);
        }
        if(this.sendMsgTimeout!=null)
        {
            producer.setSendMsgTimeout(this.sendMsgTimeout);
        }
        //如果消息发送失败，设置重试次数默认为2次
        if(this.retryTimesWhenSendFailed!=null)
        {
            producer.setRetryTimesWhenSendFailed(this.retryTimesWhenSendFailed);
        }
        try {
            producer.start();
        }
        catch (Exception e)
        {
           e.printStackTrace();

        }
        return  producer;
    }
*/
    }
